<extend name="Public/base"/>

<block name="body">
    <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
    <div class="main-title">
        <h2>创建人品大爆发活动</h2>
    </div>
    <div class="tab-wrap">
        <div class="tab-content">
            <form action="__URL__/add" method="post" class="form-horizontal" autocomplete="off">
                <div id="tab1" class="tab-pane in tab1">
                    <div class="form-item">
                        <label class="item-label">中奖物品</label>
                        <div class="controls">
                            <select name="prize" id="select_prize">
                                <foreach name="prize_type" item="vo">
                                    <option value="{$key}">{$vo}</option>
                                </foreach>
                            </select>
                        </div>
                    </div>
                    <div class="form-item">
                        <label class="item-label">标题</label>
                        <div class="controls">
                            <input type="text" class="text input-large" id="title" name="title">
                            <select class="hidden div_goods" id="select_goods">
                                <option value="0">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-item hidden div_goods">
                        <label class="item-label">商品价格</label>
                        <div class="controls">
                            <input type="text" class="text input-large" id="goods_price" name="goods_price">
                        </div>
                    </div>
                    <div class="form-item">
                        <label class="item-label">活动时间</label>
                        <div class="controls">
                            <input type="text" id="start_time" name="start_time" class="text input-mid time" placeholder="请选择时间" readonly/>
                            <span> ~ </span>
                            <input type="text" class="text input-mid time" id="end_time" name="end_time" placeholder="请选择时间"  readonly>
                        </div>
                    </div>
                    <div class="form-item">
                        <label class="item-label">总需人数</label>
                        <div class="controls">
                            <input type="text" class="text input-large" name="total_num">
                        </div>
                    </div>
                    <div class="form-item">
                        <label class="item-label">每人金额</label>
                        <div class="controls">
                            <select name="money">
                                <option value="1">1元</option>
                                <option value="5">5元</option>
                                <option value="10">10元</option>
                                <option value="20">20元</option>
                                <option value="50">50元</option>
                                <option value="100">100元</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-item">
                        <label class="item-label">图片</label>
                        <div class="controls">
                            <input type="file" id="upload_picture">
                            <input type="hidden" name="pic" id="pic_id"/>
                            <div class="upload-img-box"></div>
                        </div>
                        <script type="text/javascript">
                        //上传图片
                        /* 初始化上传插件 */
                        $("#upload_picture").uploadify({
                            "height"          : 30,
                            "swf"             : "__STATIC__/uploadify/uploadify.swf",
                            "fileObjName"     : "download",
                            "buttonText"      : "上传图片",
                            "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                            "width"           : 120,
                            'removeTimeout'   : 1,
                            'fileTypeExts'    : '*.jpg; *.png; *.gif;',
                            "onUploadSuccess" : uploadPicture,
                            'onFallback' : function() {
                                alert('未检测到兼容版本的Flash.');
                            }
                        });
                        function uploadPicture(file, data){
                            var data = $.parseJSON(data);
                            var src = '';
                            if(data.status){
                                $("#pic_id").val(data.id);
                                src = data.url || '__ROOT__' + data.path;
                                $("#pic_id").parent().find('.upload-img-box').html(
                                    '<div class="upload-pre-item"><img src="' + src + '"/></div>'
                                );
                            } else {
                                updateAlert(data.info);
                                setTimeout(function(){
                                    $('#top-alert').find('button').click();
                                },1500);
                            }
                        }
                        </script>
                    </div>
                    <div class="form-item">
                        <label class="item-label">视频</label>
                        <div class="controls">
                            <input type="file" id="upload_video">
                            <input type="hidden" name="video" id="video_id"/>
                            <div class="upload-img-box"></div>
                        </div>
                        <script type="text/javascript">
                        //上传图片
                        /* 初始化上传插件 */
                        $("#upload_video").uploadify({
                            "height"          : 30,
                            "swf"             : "__STATIC__/uploadify/uploadify.swf",
                            "fileObjName"     : "download",
                            "buttonText"      : "上传视频",
                            "uploader"        : "{:U('File/uploadMovie',array('session_id'=>session_id()))}",
                            "width"           : 120,
                            'removeTimeout'   : 1,
                            'multi'           : false,
                            'fileTypeExts'    : '*.flv; *.avi; *.wma; *.rmvb; *.rm; *.flash; *.mp4; *.mid; *.3gp;',
                            "onUploadSuccess" : uploadMovie,
                            'onFallback' : function() {
                                alert('未检测到兼容版本的Flash.');
                            }
                        });
                        var curr_video = { id: "", src: "", type: ""};
                        
                        function uploadMovie(file, data){
                            var data = $.parseJSON(data);
                            if(data.status){
                                mime = data.info.mime;
                                if (mime == undefined || mime == '') {
                                    mime = data.info.type;
                                }
                                $("#video_id").val(data.info.id);
                                curr_video.id = data.info.id, curr_video.src = '__ROOT__/Uploads/Movie/' + data.info.savepath + data.info.savename, curr_video.type = mime;
                                preloadvideo();
                            } else {
                                updateAlert(data.info);
                                setTimeout(function(){
                                    $('#top-alert').find('button').click();
                                },1500);
                            }
                        }
                        
                        function preloadvideo() {
                            if (curr_video.id == '' || curr_video.id == undefined) {
                                return false;
                            }
                            $("#upload_video").parent().find('.upload-img-box').html(
                                '<video id="myvideo" class="video-js vjs-big-play-centered" controls preload="auto" width="480" height="240" data-setup="{}"><source src="' + curr_video.src + '" type="' + curr_video.type + '"></video>'
                            );
                            videojs('myvideo').ready(function(){
                                this.preload();
                            });
                        }
                        </script>
                    </div>
                </div>

                <div class="form-item">
                    <button class="btn submit-btn ajax-post hidden" id="submit" type="submit" target-form="form-horizontal">确 定</button>
                </div>
            </form>
        </div>
    </div>
</block>

<block name="script">
    <link rel="stylesheet" type="text/css" href="__STATIC__/videojs/css/video-js-5.2.1.css" />
    <script type="text/javascript" src="__STATIC__/videojs/js/video-js-5.2.1.js"></script>
    <link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
    <php>if(C('COLOR_STYLE')=='blue_color') echo '<link href="__STATIC__/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">';</php>
    <link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
    <script type="text/javascript">
    $(function(){
        $('#start_time').datetimepicker({
            format: 'yyyy-mm-dd hh:ii',
            language:"zh-CN",
            autoclose:true
        }).on("click",function(){
            $("#start_time").datetimepicker("setEndDate", $("#end_time").val());
        });
        $('#end_time').datetimepicker({
            format: 'yyyy-mm-dd hh:ii',
            language:"zh-CN",
            autoclose:true
        }).on("click",function(){
            $("#end_time").datetimepicker("setStartDate", $("#start_time").val());
        });
        showTab();
        $("#select_prize").change(function(){
            var prize = $(this).val();
            if (prize == 'cash') {
                $(".div_goods").removeClass("hidden");
            }else{
                $(".div_goods").addClass("hidden");
            }
        });
        $('#title').bind('input propertychange', function() {
            var prize = $("#select_prize").val();
            var keyword = $(this).val();
            if (prize == 'cash' && keyword != '') {
                $.post("{:U('product/product_autocomplete')}",{'query':keyword},function(result){
                    $("#select_goods").empty();
                    $("#select_goods").append("<option value='0'>请选择</option>")
                    if (result != null) {
                        $.each(result,function(i,v){
                            if (v.type == 'putong' && v.price > 0) {
                                $("#select_goods").append("<option value='"+v.price+"'>"+v.title+"</option>")
                            }
                        })
                    }
                },'json')
            }
        });
        $("#select_goods").change(function(){
            var prize = $("#select_prize").val();
            if (prize == 'cash') {
                goods_price = $(this).val();
                goods_name = $(this).find("option:selected").text();
                if (goods_price > 0) {
                    $("#title").val(goods_name);
                    $("#goods_price").val(goods_price);
                }
            }
        })
    });
    </script>
</block>